package com.scau.ums.controller;

import com.scau.ums.mapper.CustomedNewsMapper;
import com.scau.ums.model.News;
import com.scau.ums.service.imp.news.diyNewsImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class diyShowNewsController {

    @Autowired
    private diyNewsImp diynewsimp;


    @RequestMapping(value = "/diyShowNews",method = RequestMethod.GET)
    public String toDiyShowNews()
    {
        return "diyShowNews";
    }


    @RequestMapping("/getNewsList")
    @ResponseBody
    public Map<String, Object> listNews(HttpServletRequest request){

        Map<String, Object> map = new HashMap<>();
        int curPage = Integer.parseInt(request.getParameter("curPage"));
        int sumPage = diynewsimp.getNewsPageSum();
        map.put("sumPage", sumPage);
        List<News> newsList = diynewsimp.getNewsCurPageRecords(curPage);
        map.put("newsList",newsList);

        return map;
    }
}
